home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume90
/
rexx
/
mrnbst.ime
/
MRNBSTime.vt100
< prev
next >
Wrap
Text File
|
1990-03-04
|
4KB
|
179 lines
/* This VT100 AREXX macro will try to get the precise time by calling the
** National Bureau of Standards. It captures the time string, then calls
** the program "MRNBSTime" with the result.
**
** This macro requires VT100 R2.9 and ARexx 1.10.
**/
trace OFF
if show("L", "rexxsupport.library") = 0
then call addlib "rexxsupport.library", 0, -30, 0
do
portname = "REXX-VT100"
port = openport(portname)
if Port = '0000 0000'x
then do
say "Couldn't open the port."
exit 20
end
"BAUD 1200"
"FORWARD" portname /* Enable forwarding of received data. */
if rc ~= 0 then exit
forwarding = 1
if dial("DT1-202-653-0351") = 0 /* Dial NBS. */
then do
'MSG "Dial failed."'
call cleanup 20
end
'FORWARD' /* Disable forwarding of received data. */
forwarding = 0
/* Note that this uses a file in RAM:. You might want to try using a named
* pipe (e.g. PIPE:NBSTIME) instead!
*/
"CAPTURE RAM:zzzNBSTime.text" /* Capture time code text. */
call delay 250 /* Collect approx. 5 seconds worth. */
"CAPTURE" /* Close capture buffer. */
/* Set the system date. */
address COMMAND 'MRNBSTime -h -5 RAM:zzzNBSTime.text'
/* Unless you have an incredibly slow disk drive, your clock should now be
* within 1 second of the NBS time. Don't you just feel good all over?
*/
'MSG "Ohhh...it feels so good!"'
call cleanup -1
/*
* Delete our temporary file.
*/
address COMMAND 'Delete RAM:zzzNBSTime.text'
end
exit 0
/* Dial the specified number(s). If we get no connection we keep going till
** we get a connection. If we never get one then we return 0 for failure else
** we return 1 for success.
**/
dial: procedure expose port portname
numargs = arg()
msgdata = ""
do i = 1 to numargs
'SEND "AT' || arg(i) || '^M"'
if get_match(60, "CONNECT", "BUSY", "NO") = 2
then leave
end
if i > numargs
then return 0 /* Failure */
else return 1 /* Success */
/* Get a match from the serial port via VT100. 1st arg is the maximum time
** we'll wait; subsequent args are "acceptable" match strings. We return the
** arg() index of the matched string so if we ever time out we'll return 1
** (since that's the index of the max time arg).
**/
get_match: procedure expose port portname
numargs = arg()
longest = 0
do i = 2 to numargs
longest = max(longest, length(arg(i)))
end
msgdata = ""
maxtime = arg(1)
do forever
msg = receive(maxtime)
if msg == ""
then return 1
msgdata = msgdata || msg
do i = 2 to numargs
ndx = index(msgdata, arg(i))
if ndx > 0
then leave
end
if i <= numargs
then return i
if length(msgdata) > longest
then msgdata = right(msgdata, longest - 1)
end
/* Don't use the AREXX waitpkt() function as that locks us up until something
** arrives at the port. Instead, use the AmigaDOS WAIT command or, if you have
** AREXX 1.10 or later, the AREXX delay() function.
**/
receive: procedure expose port portname
arg waittime
time = 0
packet = getpkt(portname)
do while packet = '0000 0000'x
if waittime ~= 0
then do
if time > waittime
then return ""
/* address COMMAND "WAIT 1 SEC" /* AmigaDOS */ */
call delay 50 /* AREXX 1.10 or above */
time = time + 1
end
else call waitpkt portname
packet = getpkt(portname)
end
msg = getarg(packet)
call reply packet, 0
retval = ""
do while length(msg) > 0
parse var msg first '00'x msg
retval = retval || first
end
return retval
cleanup: procedure expose port portname forwarding
arg retc
if forwarding = 1 then 'FORWARD' /* Disable forwarding. */
/* Reply all packets queued up for us. */
packet = getpkt(portname)
do while packet ~= '0000 0000'x
call reply packet, 0
packet = getpkt(portname)
end
/* This is the hangup code. Ick! Well, it does seem to work :-| */
call delay 50
'SEND "+++"' /* Put modem in command mode. */
call delay 50
'SEND "+++"' /* Pay the insurance man. */
call delay 50
'SEND "ATH^M"' /* Drop carrier. */
call delay 50
'SEND "ATH^M"' /* Did you hear me? I said DROP CARRIER! */
call closeport port
if retc = -1 then return
exit retc